@echo off
setlocal enabledelayedexpansion
:: Remove chcp 65001 and use ASCII prompts
set /p start="Enter start number: "
set /p end="Enter end number: "

:: Validate input is numeric
echo !start!| findstr /r "^[0-9]*$" >nul
if errorlevel 1 (
    echo Error: Start number must be an integer
    pause
    exit /b
)

echo !end!| findstr /r "^[0-9]*$" >nul
if errorlevel 1 (
    echo Error: End number must be an integer
    pause
    exit /b
)

:: Validate start <= end
if !start! gtr !end! (
    echo Error: Start number cannot be greater than end number
    pause
    exit /b
)

:: 循环创建文件夹
for /l %%i in (%start%, 1, %end%) do (
    mkdir "product_%%i" 2>nul
    if exist "product_%%i" (
        echo 已创建文件夹: product_%%i
        :: Copy utils folder to each product folder
        if exist "utils" (
            xcopy "utils" "product_%%i\utils" /E /I /Q
            if errorlevel 0 (
                echo Copied utils to product_%%i
            ) else (
                echo Failed to copy utils to product_%%i
            )
        ) else (
            echo Warning: utils folder not found in current directory
        )
    ) else (
        echo Failed to create: product_%%i (may already exist or no permission)
    )
)

echo 所有文件夹创建完成!
pause
